//
//  NSString+timeFormat.m
//  YuBao
//
//  Created by hok on 10/16/15.
//  Copyright © 2015 hok. All rights reserved.
//

#import "NSString+timeFormat.h"

@implementation NSString (timeFormat)

+ (NSString *)convertServerTimeToString:(NSString *)timeString
{
   // NSString *str=@"1368082020";//时间戳
    NSTimeInterval time=[timeString doubleValue]/1000;//因为时差问题要加8小时 == 28800 sec
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    //NSLog(@"date:%@",[detaildate description]);
    
    
 
    
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    return [dateFormatter stringFromDate: detaildate];
    
    
}
+ (NSString *)convertServerTimeToDay:(NSString *)timeString{
    NSTimeInterval time=[timeString doubleValue]/1000;//因为时差问题要加8小时 == 28800 sec
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    //NSLog(@"date:%@",[detaildate description]);
    
    
    
    
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    //[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    [dateFormatter setDateFormat:@"MM-dd"];
    return [dateFormatter stringFromDate: detaildate];
}
+ (NSString *)replaceAccountString:(NSString *)accountInfo
{
    NSMutableString *result = [[NSMutableString alloc] init];
    if (accountInfo.length > 10 ) {
        [result appendFormat:@"%@****%@",[accountInfo substringWithRange:NSMakeRange(0, 4)],[accountInfo substringWithRange:NSMakeRange(accountInfo.length  - 4, 4)]];
    }else{
        [result appendString: accountInfo];
    }
    return result;
}

+ (NSString *)dateString
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    //[dateFormatter setDateFormat:@"MM-dd"];
    return [dateFormatter stringFromDate: [NSDate date]];
}
@end
